#!/bin/bash

version="26.1.4"

yum install wget yum-utils device-mapper-persistent-data lvm2 -y
wget --no-check-certificate -t 0 -c https://download.docker.com/linux/static/stable/x86_64/docker-${version}.tgz
tar -xf docker-${version}.tgz
cp docker/*  /usr/bin/

cat > /usr/lib/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Environment="PATH=/bin:/sbin:/usr/bin:/usr/sbin"
Type=notify
ExecStart=/usr/bin/dockerd
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
RestartSec=5
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
EOF

mkdir -p /etc/docker

cat > /etc/docker/daemon.json << EOF
{
  "exec-opts": ["native.cgroupdriver=cgroupfs"],
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "max-concurrent-downloads": 10,
  "storage-driver": "overlay2",
  "data-root": "/data/docker",
  "registry-mirrors": ["https://9awg5swa.mirror.aliyuncs.com", "https://docker.1panelproxy.com"],
  "insecure-registries" : ["my-insecure-registry.example.com:5000"],
  "mtu": 1500
}
EOF

systemctl daemon-reload && systemctl start docker && systemctl enable docker
systemctl status docker | grep running > /dev/null
if [ $? = 0 ];then
  echo -e "\033[32mDocker ${version} install succeed !\033[0m"
else
  echo -e "\033[31mDocker ${version} install failed !\033[0m"
fi